package com.health.listener;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * routing路由模式
 */
@Component
public class Listener4 {
    /**
     * 1号消费者
     * 由于交换机类型默认为DIRECT,可以省略
     * @param msg
     */
    @RabbitListener(
            bindings = @QueueBinding(
                  value = @Queue(value = "routing.queue3"),
                  exchange = @Exchange(value = "direct.exchange",
                          type = ExchangeTypes.DIRECT
                  ),
                  key = {"flag"}
                    )
    )
    public void listener(String msg){
        System.out.println("111接收到的消息>>>"+msg);
    }

    /**
     * 2号消费者
     * @param msg
     */
    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(value = "routing.queue4"),
                    exchange = @Exchange(value = "direct.exchange"
                    ,type = ExchangeTypes.DIRECT)

            )
    )
    public void listener2(String msg){
        System.out.println("222接收到的消息>>>"+msg);
    }

}
